home *** CD-ROM | disk | FTP | other *** search
- Path: news.compuserve.com!newsmaster
- From: 73700.776@compuserve.com (Walter C. Riley)
- Newsgroups: comp.lang.c++
- Subject: Re: Using templates in BC++ 4.5
- Date: Tue, 23 Jan 1996 21:37:48 GMT
- Organization: CompuServe Incorporated
- Message-ID: <4e3khc$90r@dub-news-svc-6.compuserve.com>
- References: <31050C2D.674C@tribeca.ios.com>
- NNTP-Posting-Host: ad45-166.compuserve.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- John Leonard <leonardj@tribeca.ios.com> wrote:
-
- >I wrote a windows program, in BC++ 4.52, that uses class templates.
- >The template declarations are in a header file and the function
- >definitions are in a cpp file which includes the header file. The cpp
- >file compiled fine, but the project window showed that the code size
- >equaled zero and when I tried to build and link the entire project I got
- >linker error messages that the member functions of the class were
- >undefined. I then changed the code so that the classes weren't templates
- >and the project was built and ran fine. My question is: how can I use
- >class templates in my program?
-
- John,
-
- You want to remember that when you write a template class, you are not
- giving the compiler instructions on how to build objects from a class,
- instead you are telling the compiler how to first generate the
- specific class declarations themselves -- the code is then generated
- using these newly created specific declarations. Borland, by default,
- uses smart templates where code is only generated in a module when an
- object of the template class is created. If you are writing general
- purpose code, where you don't know exactly what classes will be built
- from your templates, then you will want all the code of your template
- classes in the header file, so that when the compiler needs to
- generate a specific instance of the template, it has the full details
- of how to do so. See the STL for good examples of template code.
-
- Good luck,
- Walt
-
-
-